﻿using Xejen.Database.Entities;
using Xejen.Database.Entities.Auditing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Xejen.Database.Ef.Sqlite.Demos
{
    /// <summary>
    /// 表示协数据传输记录表[DataTransferRecords]
    /// </summary>
    /// <creator>marc</creator>
    [Table("DataTransferRecords")]
    [Description("请求记录表")]
    public class DataTransferRecordEntity : CreationEntity<long>, IEntity<long>
    {
        /// <inheritdoc/>
        [Key]
        [Column(Order = 100)]
        [Description("主键id")]
        public override long Id { get; set; }

        /// <summary>
        /// 简易信息
        /// </summary>
        [Required]
        [Column(Order = 250)]
        [Description("简易信息")]
        public virtual string Summary { get; set; }

        /// <summary>
        /// 日志类型
        /// </summary>
        [Column(Order = 300)]
        [Description("日志类型")]
        public short RecordType { get; set; }

        /// <summary>
        /// 传输数据
        /// </summary>
        [Column(Order = 400)]
        [Description("传输数据")]
        public string Data { get; set; }

        /// <summary>
        /// 处理状态
        /// </summary>
        [Column(Order = 500)]
        [Description("处理状态")]
        public short HandleStatus { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        [Column(Order = 600)]
        [Description("错误信息")]
        public string ErrorMessage { get; set; }

        /// <summary>
        /// 请求耗时的总毫秒数
        /// </summary>
        [Column(Order = 700)]
        [Description("请求耗时的总毫秒数")]
        public double DurationTotalMilliseconds { get; set; }

        /// <summary>
        /// 请求耗时
        /// </summary>
        [NotMapped]
        public TimeSpan Duration
        {
            get { return TimeSpan.FromMilliseconds(DurationTotalMilliseconds); }
            set { DurationTotalMilliseconds = value.TotalMilliseconds; }
        }

        /// <summary>
        /// 请求起时时间
        /// </summary>
        [Column(Order = 800)]
        [Description("请求起时时间")]
        public DateTime StartTime { get; set; }

        /// <summary>
        /// 请求结束时间
        /// </summary>
        [Column(Order = 900)]
        [Description("请求结束时间")]
        public DateTime EndTime { get; set; }

        /// <inheritdoc cref="DataTransferRecordEntity"/>
        public DataTransferRecordEntity()
        {
            CreationTime = StandardTime.Now;
        }
    }
}
